#include "SeqList.h"
#include<iostream>
using namespace std;

template<typename T>
SeqList<T>::SeqList(int nSize)
{
	m_pData=new T[nSize+1];
	m_nTotalSize=nSize;
	m_nValideSize=0;
}

template<typename T>
SeqList<T>::~SeqList()
{
	cout<<"deconstructor"<<endl;
	delete[] m_pData;
}

template<typename T>
void SeqList<T>::Add(T value)
{
	if (m_nValideSize<=m_nTotalSize)
	{
		m_pData[m_nValideSize]=value;
		m_nValideSize++;
	}
	else
	{
		m_nTotalSize=2*m_nTotalSize;
		T *p=new T[m_nTotalSize+1];
		for (int i=0; i<m_nValideSize; i++)
		{
			p[i]=m_pData[i];
		}
		p[m_nValideSize]=value;
		m_nValideSize++;
		delete[] m_pData;
		m_pData=p;
	}
}

template<typename T>
void SeqList<T>::PrintList()
{
	for (int i=0; i<m_nValideSize; i++)
	{
		cout<<m_pData[i]<<endl;
	}
}

template<typename T>
int SeqList<T>::GetSize() const
{
	return m_nValideSize;
}

template<typename T>
T SeqList<T>::Get(int pos)
{
	if(pos>=m_nValideSize)
	{
		cout<<"error"<<endl;
		return -1;
	}
	else
		return m_pData[pos];
}
